@echo off
chcp 65001 >nul
echo ================================================
echo    日志分析平台微服务 - 一键启动脚本
echo ================================================
echo.

echo [1/4] 检查Nacos是否运行...
curl -s http://localhost:8848/nacos >nul 2>&1
if %errorlevel% neq 0 (
    echo [警告] Nacos未运行，请先启动Nacos！
    echo 启动命令: cd nacos/bin && startup.cmd -m standalone
    pause
    exit /b 1
)
echo [√] Nacos已运行

echo.
echo [2/4] 编译项目...
call mvn clean package -DskipTests
if %errorlevel% neq 0 (
    echo [×] 编译失败！
    pause
    exit /b 1
)
echo [√] 编译成功

echo.
echo [3/4] 启动微服务...
echo.

echo 启动日志分析服务 (端口8081)...
start "Log Analysis Service" cmd /k "cd log-analysis-service && mvn spring-boot:run"
timeout /t 30 /nobreak >nul

echo 启动日志测试服务 (端口8082)...
start "Log Test Service" cmd /k "cd log-test-service && mvn spring-boot:run"
timeout /t 20 /nobreak >nul

echo 启动API网关 (端口8080)...
start "API Gateway" cmd /k "cd log-analysis-gateway && mvn spring-boot:run"
timeout /t 20 /nobreak >nul

echo.
echo [4/4] 启动前端...
start "Frontend" cmd /k "cd frontend && npm run dev"

echo.
echo ================================================
echo    所有服务启动完成！
echo ================================================
echo.
echo 访问地址:
echo   前端应用: http://localhost:3000
echo   API网关: http://localhost:8080
echo   Nacos控制台: http://localhost:8848/nacos
echo.
echo 默认账号: admin / admin123
echo.
pause

